<template>
    <div class="">
        <el-dialog
                :title="title"
                :visible.sync="dialogFormVisible"
                width="900px"
                :close-on-click-modal="false"
                @close="close"
        >
            <div>
                <el-table
                        :data="list"
                        stripe
                        style="width: 100%">
                    <el-table-column
                            prop="id"
                            label="排名"
                    >
                    </el-table-column>
                    >
                    <el-table-column
                            prop="name"
                            label="商品名称"
                    >
                    </el-table-column>
                    <el-table-column
                            prop="count"
                            label="销量"
                    >
                    </el-table-column>
                    >
                    <el-table-column
                            prop="money"
                            label="销售额(元)">
                    </el-table-column>
                </el-table>
                <el-pagination
                        background
                        layout="prev, pager, next"
                        :total="page.total"
                        :page-size="page.pagesize"
                        :current-page.sync='page.currentPage'
                        @current-change="handleCurrentChange">
                </el-pagination>
            </div>
            <div slot="footer" class="dialog-footer">
                <el-button size="medium" @click="close">取 消</el-button>
                <el-button size="medium" type="primary" @click="save">确 定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
    import {goodsRank} from "@/api/statistics";
    import {changeDate} from "@/utils/index";
    import {mapState} from "vuex";
    export default {
        name: "labelSave",
        created() {
        },
        data() {
            return {
                title: "",
                dialogFormVisible: false,
                list: [],
                listLoading: true,
                selectRows: "",
                elementLoadingText: "正在加载...",
                page: {
                    total: 0,
                    size: 10,
                    currentPage: 1,
                },
                time:[],
                storeId:'',
            }
        },
        components: {
        },
        methods: {
            showEdit(row) {
                if (!row) {
                    this.title = "更多商品";
                    this.init()
                } else {
                    this.title = "更多商品";
                    this.time = row
                    this.init()
                    // this.form = Object.assign({}, row);
                }
                this.dialogFormVisible = true;
            },
            setStoreId(storeId){
                this.storeId = storeId
            },
            async init(){
                let startTime = '';
                let endTime = '';
                if(this.time){
                    startTime  = changeDate(this.time[0]);
                    endTime = changeDate(this.time[1]);
                }
                var params = {
                    page: this.page.currentPage,
                    startTime,
                    endTime,
                    storeId:this.storeId,
                }
                const { data,count} = await goodsRank(params);
                this.list = data;
                this.page.total = count;
            },
            handleCurrentChange(val) {
                this.page.currentPage = val;
                this.init();
            },
            close() {
                // this.$refs["form"].resetFields();
                // this.form = this.$options.data().form;
                this.dialogFormVisible = false;
            },
            save() {
                this.close();
                // this.$refs["form"].validate(async (valid) => {
                //     if (valid) {
                //         const { msg } = await labelSave(this.form);
                //         this.$baseMessage(msg, "success");
                //         this.$emit("fetchData");
                //         this.close();
                //     } else {
                //         return false;
                //     }
                // });
            },
        }
    };
</script>
